/**
 * Created by guojianyu on 2016/3/3.
 */
var app=angular.module('register',[]);
/*用户注册*/
app.controller('registerController',function($scope,$http){
    $scope.row = {};
    $scope.userRegister=function(name,email,address,password,phone,sex){
        /*标志位防止重复添加数据*/
        if ($scope.row.isUpload) {
            return;
        }
        $scope.row.isUpload = true;
        if(name==''||email==''||address==''||password==''||phone==''||sex==''
        ||name==undefined||email==undefined||address==undefined||password==undefined||phone==undefined||sex==undefined){
            alert("请填写用户完整信息")
        }else {
            $http.post('user/register', $scope.user).success(
                function (data) {
                    if (data == true) {
                        alert("注册成功");
                        window.location.href = "/web/"
                        $scope.row.isUpload = false;
                    } else {
                        alert("注册失败");
                        $scope.row.isUpload = false;
                    }
                }
            ).error(
                function () {
                    alert("注册失败");
                    $scope.row.isUpload = false;
                }
            )
        }
    };
    /*用户注册页面-点击按钮返回登录页*/
    $scope.return=function(){
        window.location.href = "/web/"
    }

});
/*商家注册*/
app.controller('businessRegisterController',function($scope,$http){
    $scope.business = {};
    $scope.businessRegister=function(name,address,password,phone){
        /*标志位防止重复添加数据*/
        if ($scope.business.isUpload) {
            return;
        }
        $scope.business.isUpload = true;
        if(name==''||address==''||password==''||phone==''
            ||name==undefined||address==undefined||password==undefined||phone==undefined){
            alert("请填写商家完整信息")
        }else {
            $http.post('business/businessRegister', $scope.business).success(
                function (data) {
                    if (data == true) {
                        alert("注册成功");
                        window.location.href = "/web/"
                        $scope.business.isUpload = false;
                    } else {
                        alert("注册失败");
                        $scope.business.isUpload = false;
                    }
                }
            ).error(
                function () {
                    alert("注册失败");
                    $scope.row.isUpload = false;
                }
            )
        }
    };
    /*商家注册页面-点击按钮返回登录页面*/
    $scope.return=function(){
        window.location.href = "/web/"
    }
});

